# -*- encoding: utf-8 -*-
# 
# Lúcuma
# Copyright © 2008 Diego Escalante Urrelo  <diegoe@gnome.org>
# 
# Licensed under the GNU General Public License Version 2
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor
# Boston, MA  02110-1301, USA.
# 

from django import template
from lucuma.personas.models import Persona
from lucuma.tasks.forms import InlineTaskForm

register = template.Library()

def task_single(context):
    """
    Renders a single Task.
        tasks_tags_checkbox: If True, show the checkbox.
        tasks_tags_preview: Add a preview of the Task body.
        tasks_tags_reply: If this is a reply, show to what.
        tasks_tags_date: Show the due date.
        tasks_tags_actions: Add a [x] at the end of the Task.
        tasks_tags_responsible: Show the responsible of this Task.
        tasks_tags_sidebar: Whether to enhance this for a sidebar.
        tag_name: Tag name to boldify.
    """
    return {
        'task':                     context.get('task', None),
        'tasks_tags_checkbox':      context.get('tasks_tags_checkbox', True),
        'tasks_tags_preview':       context.get('tasks_tags_preview', True),
        'tasks_tags_reply':         context.get('tasks_tags_reply', True),
        'tasks_tags_date':          context.get('tasks_tags_date', True),
        'tasks_tags_actions':       context.get('tasks_tags_actions', True),
        'tasks_tags_responsible':   context.get('tasks_tags_responsible', True),
        'tasks_tags_sidebar':       context.get('tasks_tags_sidebar', False),
        'tag_name':                 context.get('tag_name', None),
        'session':                  context.get('session', None),
        }

def task_sidebar_list(context):
    """
    Shows a Task list that fits the sidebar (profile). Takes the same arguments
    than tasks_single.
    """
    return {
        'task':                     context.get('task', None),
        'tasks_tags_checkbox':      context.get('tasks_tags_checkbox', True),
        'tasks_tags_preview':       context.get('tasks_tags_preview', False),
        'tasks_tags_reply':         context.get('tasks_tags_reply', False),
        'tasks_tags_date':          context.get('tasks_tags_date', True),
        'tasks_tags_actions':       context.get('tasks_tags_actions', False),
        'tasks_tags_responsible':   context.get('tasks_tags_responsible', False),
        'tasks_tags_sidebar':       context.get('tasks_tags_sidebar', True),
        'tag_name':                 context.get('tag_name', None),
        'session':                  context.get('session', None),
        }

def task_add(context):
    """
    Renders the Task add form.
    """
    if context.get('note') is not None:
        data = {'reply': context['note'].id}
    else:
        data = {}

    form = InlineTaskForm(data)

    return {
        'session':      context.get('session', None),
        'form':         form,
        }

register.inclusion_tag('task_task.html', 
                        takes_context=True)(task_single)
register.inclusion_tag('task_task.html', 
                        takes_context=True)(task_sidebar_list)
register.inclusion_tag('task_add.html', 
                        takes_context=True)(task_add)
